/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import dao.DaoEmploye;
import dao.DaoGeneric;
import factory.FactoryDao;
import java.util.List;
import model.metier.Employe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

/**
 *
 * @author biron
 */
@Controller
//@SessionAttributes("client")
@RequestMapping(value = {"/employe"})
public class EmployeController {

    private FactoryDao factory;

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(Model model) {
        model.addAttribute("employe", new Employe());
        return "login";
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String login(@ModelAttribute(value = "employe") Employe employe, Model model) {
        DaoEmploye dao = (DaoEmploye) factory.getDao(employe.getClass());
        Employe empl = dao.connection(employe);
        if (empl != null) {
            model.addAttribute("employe", empl);

        } else {
             model.addAttribute("msgErreur", "ko!!");
        }
        return "index";
    }

//    @RequestMapping(value = "/inscription", method = RequestMethod.GET)
//    public String inscription(Model model) {
//
//        model.addAttribute("user", new Clients());
//        return "inscription";
//    }
//
//    @RequestMapping(value = "/inscription", method = RequestMethod.POST)
//    public String inscription(@ModelAttribute(value = "user") Clients user) {
//        DaoGeneric dao = factory.getDao(Clients.class);
//        dao.insert(user);
//        return "index";
//
//    }
//    @RequestMapping("/inscription")
//    public ModelAndView inscription(){
//        
//        ModelAndView model = new ModelAndView("inscription");
//        model.addObject("user", new User());
//        return model;
//    }

    
    
    
    
//    @ModelAttribute(value = "lVilles")
//    public List<Villes> listeVilles() {
//        DaoGeneric dao = factory.getDao(Villes.class);
//        List<Villes> l = dao.selectAll(Villes.class);
//        return l;
//    }
    
    
    
    

    public FactoryDao getFactory() {
        return factory;
    }

    @Autowired
    public void setFactory(FactoryDao factory) {
        this.factory = factory;
    }

}
